package com.example.demo.controller;

import com.example.demo.entity.Role;
import com.example.demo.entity.User;
import com.example.demo.service.RoleService;
import com.example.demo.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

/**
 * @author moguai
 * @version 1.0
 * @date 2022/3/18 13:09
 */
@RestController
@RequestMapping("/api")
@Api(tags = "角色操作")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @Autowired
    @Qualifier(value = "userRoleServiceImpl")
    private UserRoleService user_roleService;
    @ApiOperation("查找")
    @RequestMapping(value ="/role", method = RequestMethod.GET)
    public Role SelectRole(Integer id){
        return roleService.SelectRole(id);
    }
    @ApiOperation("插入")
    @RequestMapping(value ="/role", method = RequestMethod.POST)
    public void InsertRole(Role role){
        roleService.InsertRole(role.getRole_id(),role.getRole_name());
    }
    @ApiOperation("更新")
    @RequestMapping(value ="/role", method = RequestMethod.PUT)
    public void UpdateRole(Role role){
        roleService.UpdateRole(role.getRole_id(),role.getRole_name());
    }
    @ApiOperation("删除")
    @RequestMapping(value ="/role", method = RequestMethod.DELETE)
    public void DeleteRole(Integer id){
        roleService.DeleteRole(id);
        user_roleService.DeleteUser_RoleByRole(id);
    }
}
